package org.example.advise;

import org.example.model.common.Response;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: Ran
 * @Date: 2021/9/17
 **/

@RestControllerAdvice
public class ExceptionHandlerAdvice {

    /**
     * 全局异常处理 code 500
     * @param throwable
     * @return
     */
    @ExceptionHandler(Throwable.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Response exception(Throwable throwable) {

        return Response.buildFailure("500", "服务器错误");
    }

}
